<template>
  <div class="pay-result-container">
    <div class="result-card">
      <div class="result-icon" :class="payStatus === 'success' ? 'success' : 'failure'">
        {{ payStatus === 'success' ? '✓' : '✗' }}
      </div>
      <h1 class="result-title">{{ payStatus === 'success' ? '支付成功' : '支付失败' }}</h1>
      <p class="result-desc">{{ payStatus === 'success' ? '您的订单已支付成功，感谢您的购买！' : '支付未完成，请重新尝试支付。' }}</p>
      
      <div class="order-info">
        <div class="info-item">
          <span class="label">订单号：</span>
          <span class="value">{{ orderId || '-' }}</span>
        </div>
        <div class="info-item">
          <span class="label">支付金额：</span>
          <span class="value">¥{{ amount || '-' }}</span>
        </div>
        <div class="info-item">
          <span class="label">支付时间：</span>
          <span class="value">{{ payTime || '-' }}</span>
        </div>
      </div>
      
      <el-button type="primary" @click="backToOrderList" class="back-btn">返回订单列表</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'PayResult',
  data() {
    return {
      payStatus: 'success', // success or failure
      orderId: '',
      amount: '',
      payTime: ''
    };
  },
  created() {
    // 从URL参数中获取支付信息
    const urlParams = new URLSearchParams(window.location.search);
    this.orderId = urlParams.get('out_trade_no') || '';
    this.amount = urlParams.get('total_amount') || '';
    const tradeStatus = urlParams.get('trade_status') || 'TRADE_SUCCESS';
    
    // 设置支付状态
    this.payStatus = (tradeStatus === 'TRADE_SUCCESS' || tradeStatus === 'TRADE_FINISHED') ? 'success' : 'failure';
    
    // 设置支付时间
    const now = new Date();
    this.payTime = now.toLocaleString();
  },
  methods: {
    backToOrderList() {
      // 返回订单列表功能
      this.$message.info('返回订单列表功能待实现');
      // 这里可以添加实际的跳转逻辑
      // this.$router.push('/billing');
    }
  }
};
</script>

<style scoped>
.pay-result-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #f5f5f5;
  padding: 20px;
}

.result-card {
  width: 100%;
  max-width: 500px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  padding: 40px;
  text-align: center;
}

.result-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: bold;
}

.success {
  background-color: #e8f4e8;
  color: #28a745;
}

.failure {
  background-color: #f9e8e8;
  color: #dc3545;
}

.result-title {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 10px;
  color: #333;
}

.result-desc {
  font-size: 16px;
  color: #666;
  margin-bottom: 30px;
}

.order-info {
  text-align: left;
  background-color: #f8f9fa;
  padding: 20px;
  border-radius: 4px;
  margin-bottom: 30px;
}

.info-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.info-item:last-child {
  margin-bottom: 0;
}

.label {
  font-weight: bold;
  color: #333;
}

.value {
  color: #666;
  text-align: right;
}

.back-btn {
  width: 100%;
  padding: 12px;
  font-size: 16px;
}
</style>